home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 402 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.9 KB

  1. From: boukanov@hadron.fi.uib.no (Igor Boukanov)
  2. Message-ID: <4gf60c$cdt@ugress.uib.no>
  3. X-Original-Date: 21 Feb 1996 13:17:00 GMT
  4. Path: in2.uu.net!bounce-back
  5. Date: 21 Feb 96 13:54:01 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: Namespace extension
  9. Organization: Fysisk institutt, Universitetet i Bergen
  10. References: <4g2aj2$bko@ugress.uib.no> <4g5e4v$cvi@peippo.cs.tut.fi>
  11. X-Newsreader: TIN [version 1.2 PL2]
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMSsxvuEDnX0m9pzZAQGhNwF/Vq1pMnJopwcexF0/O3DFSpHZAAF6H6Pe
  14.     uHlPHAipklQ6J6POOdMxBTi6w586/df0
  15.     =ZmFB
  16.  
  17. Pulkkinen Esa (esap@cs.tut.fi) wrote:
  18. > This raises immediately the following questions:
  19.  
  20. > template <class T> namespace { // an unnamed namespace template - allowed?
  21. >   int i; // how many copies of this will be in the program?
  22. >                 // what's the syntax for accessing the variable?
  23. >                 // i<T> ?  <T>::i ?
  24. >   typedef vector<T>::iterator vector_iterator;  // is this the same
  25. >                                                 // as a typedef template?
  26. > }
  27.  
  28.   From the general point of view such lines would not be allowed becouse 
  29. they can be written as 
  30. template <class T> namespace unique { 
  31.  ...
  32. }
  33. using namespace unique<T>;
  34.  
  35. but namespace unique is predefined and template names can not be 
  36. overloaded.  
  37.  
  38.  
  39. > template <class T> namespace X { int f(); }
  40.  
  41. > template <class T> using X<T>::f(); // Allowed?
  42. > template <class T> using namespace X<T>; // Allowed?
  43.  
  44. > [points to justify namespace templates removed]
  45.  
  46. I agree that such lines should not be allowed. But this would not be another
  47. rule about template namespace, I propose to extend the template to allow 
  48. template namespace declarations, NOT a template "using" declarations.
  49. And this does not prohibit next lines:
  50.  
  51. template<class T> namespace A {
  52.    void f(T);
  53.    ...
  54. }    
  55.  
  56. template<class T> namespace B {
  57.    using A<T>;
  58.    ...
  59.    void g(T t) { return f(t); } // call A<T>::f
  60. }
  61.  
  62. > >  3. It makes C++  easy to study, because somebody will have to know only 
  63. > >the general idea about templates and how to apply them to any C++ elements
  64. > >(function, class, namespase,...).  
  65.  
  66. > This would only be true if also typedef templates and union templates
  67. > were introduced too.
  68. > -- 
  69.  
  70. I agree that reason 3 should be removed. But here is another reason:
  71.    Non-template class with only public static members can be replaced by 
  72. namespace declaration. But why template class with only public static 
  73. members could not be replaced by corresponding template namespace?
  74.    
  75. --
  76. Regards, Igor Boukanov (igor.boukanov@fi.uib.no).
  77. ---
  78. [ To submit articles: try just posting with your news-reader.
  79.                       If that fails, use mailto:std-c++@ncar.ucar.edu
  80.   FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  81.   Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  82.   Comments? mailto:std-c++-request@ncar.ucar.edu.
  83. ]
  84.